﻿
using UnityEngine;

public abstract class PanelBase : MonoBehaviour
{

    [HideInInspector]
    public CanvasGroup canvasGroup;

    private bool isShow = false;

    void Awake()
    {
        canvasGroup = this.GetComponent<CanvasGroup>();
        if (canvasGroup == null)
            canvasGroup = this.gameObject.AddComponent<CanvasGroup>() as CanvasGroup;
        RegisterListeners();

    }

    public virtual void RegisterListeners()
    {

    }

    void Update()
    {
        if(isShow)
            PanelUpdate();
    }


    public virtual void PanelUpdate()
    {

    }


    //显示
    public virtual void Show()
    {
        isShow = true;
        canvasGroup.alpha = 1;
        //该组是否可交互（组下的元素是否处于启用状态）。
        canvasGroup.interactable = true;
        //该组是否阻止射线投射（允许碰撞）。
        canvasGroup.blocksRaycasts = true;
    }

    //隐藏
    public virtual void Hide()
    {
        isShow = false;
        canvasGroup.alpha = 0;
        canvasGroup.interactable = false;
        canvasGroup.blocksRaycasts = false;
    }

}
